package com.gurun.camera.addDevice.model;

import com.danale.sdk.Danale;
import com.danale.video.jni.DanaAirLink;
import com.danale.video.sdk.device.constant.WifiEnctype;
import com.gurun.camera.addDevice.entity.WifiInfoEntity;
import com.gurun.camera.addDevice.util.WifiCache;
import com.gurun.camera.addDevice.util.WifiUtil;

/**
 * Created by Administrator on 2016/9/20.
 */
public class SmarAddModelImpl implements ISmartAddModel {

    private volatile boolean mIsAirLinkStarted = false;


    @Override
    public void startSmartAdd(WifiInfoEntity entity) {
        WifiCache.getInstance().saveWifiInfo(entity);

        if(isAirLinkStarted()){
            return;
        }

        setIsAirLinkStarted(true);
        DanaAirLink.NetConfigInfo info = new DanaAirLink.NetConfigInfo(entity.getSsid(),entity.getPassword()
                , WifiEnctype.getEnctype(WifiUtil.getCapabilities(Danale.get().getBuilder().getContext(),entity.getSsid())).getNum());
        DanaAirLink.start(info,3600 * 1000,null);
    }

    @Override
    public void stopSmartAdd() {
        if(!isAirLinkStarted()){
            return;
        }
        setIsAirLinkStarted(false);
        DanaAirLink.stop();
    }

    public boolean isAirLinkStarted() {
        return mIsAirLinkStarted;
    }

    public void setIsAirLinkStarted(boolean isAirLinkStarted) {
        this.mIsAirLinkStarted = isAirLinkStarted;
    }
}
